<?php
$id=intval($_GET['id']);


if(isset($_POST['ajax_pagination'])){
			$cache=new cache;
			$og_url=$_POST['url']."/";
			$_GET['page']=$_POST['page'];
			$sql ="SELECT * from blog_comment where blog_id=$id  order by id asc ";
			$sql2="SELECT id from blog_comment where  blog_id=$id ";
			
			$pager = new Pagination($sql, 2, 5,$og_url,0,"blog_get_comment");
			$pager->ajax=1;
			$pager->setDebug(false);
			$cache=new cache;
			$data['comment']['info'] = $pager->paginate($cache,$sql2);
			$data['comment']['nav']	= $pager->renderFullNav();
			
			//Render data-------------
			
				 echo $data['comment']['nav'];
				if($data['comment']['info']){
						$url=$_POST['url'];
						echo blog_render_comment_ajax($data['comment']['info'],$data['upload_user'],$url);
				 }
				 
				 echo $data['comment']['nav'];
				 exit();
}



$db=new db;
$db->connect();
$db->query("select * from blog_post where id=".$id);
if($db->num_rows()>0){
		$data=$db->fetchOne();
		if($data['status']==0){
			die("Bài Viết Chưa được duyệt");	
		}
		//GET BAI VIET CO TAG LIEN QUAN
		if($data['tag']!=''){
			$db->query("select * from blog_post where tag='".$data['tag']."' and id !=".$id." order by id asc limit 0,6");
			if($db->num_rows()>0){
			$data['tag_data']=$db->fetchAll();
			}
		}
		//GET BAI VIET CUNG USER
	
		$db->query("select * from blog_post where upload_user='".$data['upload_user']."' and id !=".$id." order by id desc limit 0,6");
	
		if($db->num_rows()>4){
			$data['same_user']=$db->fetchAll();
			
		}
		
		//GET USER INFOR-------------
		$db->query("select name,avatar,username,date_registered,slogan,chuky from users where username='".$data['upload_user']."'");
		$data['user']=$db->fetchOne();
		//End get userinfor

		//close db connect
		$db->close();
		
		
		//GET CATEGORY CỦA BAI VIET
		$data['category']=blog_get_category_of_item($data['category'],$data['subcategory']);
		
		
		//Paging comment------------------------
			$cache=new cache;
			$og_url=blog_url_item($data['id'],$data['alias'])."/";
	
			$sql ="SELECT * from blog_comment where blog_id=$id  order by id asc ";
			$sql2="SELECT id from blog_comment where  blog_id=$id ";
			
			$pager = new Pagination($sql, 2, 5,$og_url,0,"blog_get_comment");
			$pager->ajax=1;
			$pager->setDebug(false);
			$cache=new cache;
			$data['comment']['info'] = $pager->paginate($cache,$sql2);
			$data['comment']['nav']	= $pager->renderFullNav();
		//End paging comment------------------
		
		
		
		
}else{
			die("Bài Viết Không  Tồn Tại");	
}

$db->close();
//VIEW -----
blog_view($id);
//------

$data1['canonical']=blog_url_item($data['id'],$data['alias']);
$data1['title']=web_title($data['name']);
$data1['keyword']=web_keyword($data['alias'].",".$data['name']);
$data1['mota']=web_des($data['description']);
loadview('template/header_blog',$data1);
loadview("blog/view",$data);
loadview('template/footer_video');
exit();